<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>

<body>
<input type="text" id="input">
<textarea name="" id="result" cols="30" rows="10"></textarea>

<script>
    //受限判断当前浏览器支不支持web Workers
    if(!window.Worker){
        alert("你的电脑不支持web Workers");
    }

    //然后生成一个新的线程
    let myWorker = new Worker('worker_ceshi.js');

    myWorker.onerror  = function (e) {
        console.log(e.message);//报错信息
        console.log(e.filename);//报错文件路径
    };

    //获取到input
    let input = document.getElementById("input");

    //绑定事件
    input.oninput = function () {
        //通过web worker对象将数据传递给web worker线程
        myWorker.postMessage(input.value);
    };
    //获取到web worker 里面的返回信息，并填充到textarea里面
    let result = document.getElementById("result");

    myWorker.onmessage = function (e) {
        result.textContent = e.data;
        console.log('获取到从worker里面传递的信息');
    }

</script>
</body>

</html>